using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Runtime.CompilerServices;
using UnityEngine;
using UnityEngine.Events;
using QFramework;


namespace M13.Base
{
    public class PublicMono : Singleton<PublicMono>
    {
        public event Action OnUpdateEvent;
        public event Action OnFixUpdateEvent;
        public event Action OnLateUpdateEvent;

        private MonoController _controller;


        public PublicMono()
        {
            GameObject obj = new GameObject("MonoController");
            _controller = obj.AddComponent<MonoController>();
        }
        private void Update()
        {
            OnUpdateEvent?.Invoke();
        }
        private void FixedUpdate()
        {
            OnFixUpdateEvent?.Invoke();
        }
        private void LateUpdate()
        {
            OnLateUpdateEvent?.Invoke();
        }
        public void AddUpdateListener(UnityAction fun)
        {
            _controller.AddUpdateListener(fun);
        }
        public void DeleteUpdateListener(UnityAction fun)
        {
            _controller.DeleteUpdateListener(fun);
        }
        public Coroutine StartCoroutine(string methodName)
        {
            return _controller.StartCoroutine(methodName);
        }
        public Coroutine StartCoroutine(string methodName, [DefaultValue("null")] object value)
        {
            return _controller.StartCoroutine(methodName, value);
        }
        public Coroutine StartCoroutine(IEnumerator routine)
        {
            return _controller.StartCoroutine(routine);
        }
        public Coroutine StartCoroutine_Auto(IEnumerator routine)
        {
            return _controller.StartCoroutine(routine);
        }
        public void StopCoroutine(IEnumerator routine)
        {
            _controller.StopCoroutine(routine);
        }
        public void StopCoroutine(Coroutine routine)
        {
            _controller.StopCoroutine(routine);
        }
        [MethodImpl(MethodImplOptions.InternalCall)]
        public extern void StopCoroutine(string methodName);
        [MethodImpl(MethodImplOptions.InternalCall)]
        public extern void StopAllCoroutines();
    }
}

